package com.sfx.算法专题.位运算;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-08-21
 * Time: 10:49
 */
public class Code_6_isUnique {
    static class Solution {
        public boolean isUnique(String astr) {
            if(astr.length() == 0) return true;
            if(astr.length()>=26) return false;
            char[] s = astr.toCharArray();
            int res = 0;//位图-->一个数字的二进制位表示哈希表
            for (char c : s) {
                int x = c - 'a';
                if (((res >> x) & 1) != 1) {
                    res |= (1 << x);
                } else {
                    return false;
                }
            }
            // res != 0 没有重复字符出现
            return res != 0;
        }
    }
}